package net.wanho.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import net.wanho.mapper.IndexMapper;
import net.wanho.service.IndexService;
import net.wanho.vo.InventVo;
import net.wanho.vo.PageInfo;
import net.wanho.webSocket.WebSocketServer;
import org.springframework.stereotype.Service;

/**
 * 这个类是：
 *
 * @author: MENG HU WANG
 * @date: 2025/2/7 15:50
 * @version: 1.0
 */
@Service
@RequiredArgsConstructor
public class IndexServiceImpl implements IndexService {
    private final IndexMapper indexMapper;
    private final WebSocketServer webSocketServer;

    @Override
    public PageInfo<InventVo> inventWarning(Integer pageNum, Integer pageSize) {
        Page<InventVo> page = new Page<>(pageNum, pageSize);

        Page<InventVo> inventVoPage = indexMapper.findInventPage(page);

        PageInfo<InventVo> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(inventVoPage.getCurrent());
        pageInfo.setPageSize(inventVoPage.getSize());
        pageInfo.setTotalNum(inventVoPage.getTotal());
        pageInfo.setPageCount(inventVoPage.getPages());
        pageInfo.setResultList(inventVoPage.getRecords());

        webSocketServer.sendToAllClient("库存预警!请及时补货");
        return pageInfo;
    }

    @Override
    public PageInfo<InventVo> overdueWarning(Integer pageNum, Integer pageSize) {
        Page<InventVo> page = new Page<>(pageNum, pageSize);

        Page<InventVo> inventVoPage = indexMapper.findOverduePage(page);

        PageInfo<InventVo> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(inventVoPage.getCurrent());
        pageInfo.setPageSize(inventVoPage.getSize());
        pageInfo.setTotalNum(inventVoPage.getTotal());
        pageInfo.setPageCount(inventVoPage.getPages());
        pageInfo.setResultList(inventVoPage.getRecords());
        return pageInfo;
    }
}
